package com.mindata.blockchain.core.sqlite.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.sqlite.SQLiteDataSource;

/**
 * 配置sqlite数据库的DataSource
 * 
 * @author wuweifeng wrote on 2018/3/2.
 */
@Configuration
public class DataSourceConfiguration {
	@Value("${sqlite.dbName}")
	private String dbName;

	@Bean(destroyMethod = "", name = "EmbeddeddataSource")
	public DataSource dataSource() {
		final DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
		dataSourceBuilder.driverClassName("org.sqlite.JDBC");
		dataSourceBuilder.url("jdbc:sqlite:" + dbName);
		dataSourceBuilder.type(SQLiteDataSource.class);
		return dataSourceBuilder.build();
	}

}
